package com.hwl.lab.service;

import com.hwl.lab.entity.Chronic;
import com.hwl.lab.repository.ChronicRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChronicService {
    @Autowired
    private ChronicRepository chronicRepository;
    //分页实现
    public Page<Chronic> findAll(Integer page, Integer size){
        Pageable pageable=  PageRequest.of(page-1,size);
        return chronicRepository.findAll(pageable);
    }
    //不分页
    public List<Chronic> findAll() {
        return chronicRepository.findAll();
    }
    //通过账号查询
    public Chronic findByChronicid(String chronicid){
        return chronicRepository.findByChronicid(chronicid);
    }
    //通过账号查询
    public Chronic findByChengid(String chengid){
        return chronicRepository.findByChengid(chengid);
    }
    //保存，修改
    public Chronic saveChronic(Chronic chronic){
       return  chronicRepository.save(chronic);
    }
    //通过账号删除
    public void deleteById(Long id){
        chronicRepository.deleteById(id);
    }
}
